import axios from 'axios';
import { message } from 'antd';

/**
 *
 *
 * @export
 * @param {string} url
 * @param {object} [data={}]
 * @param {string} [method='GET']
 * @return {Promise} 
 */
export default function ajax(url, data = {}, method = 'GET') {

    return new Promise((resolve) => {
        let promise = null;
        if (method === 'GET') {
            promise = axios.get(url, {
                params: data
            });
        } else if (method === 'POST') {
            promise = axios.post(url, data);
        }

        promise.then(response => {
            resolve(response.data);
        }).catch(err => {
            message.error('请求出错：' + err.message);
        })
    });
}